package com.xian.im.modules.security;

import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author wen.zhang
 */
@Data
@Builder
public class BaseClaims implements Serializable {
    private static final long serialVersionUID = 42L;

    private static  final String ONLINE_KEY = "online:token";

    private static  final  String MARK = ":";

    private Long userId;

    private String channel;

    private String userAccount;

    private String redisKey;

    private String token;

    private Long orgId;

    private Integer type;

    private String ak;

    private String sk;

    public String getRedisKey(){
        if(StringUtils.isNotBlank(userAccount)){
            return getUserRedisKey();
        }else {
            return getOrgRedisKey();
        }
    }
    public String getUserRedisKey() {
        StringBuffer sb = new StringBuffer();
        sb.append(ONLINE_KEY)
                .append(MARK)
                .append(orgId)
                .append(MARK)
                .append(userId)
                .append(MARK)
                .append(userAccount)
                .append(MARK)
                .append(type)
                .append(MARK)
                .append(channel);
        return sb.toString();
    }

    public String getOrgRedisKey() {
        StringBuffer sb = new StringBuffer();
        sb.append(ONLINE_KEY)
                .append(MARK)
                .append(orgId)
                .append(MARK)
                .append(ak)
                .append(MARK)
                .append(sk)
                .append(MARK)
                .append(type);
        return sb.toString();
    }
}
